#!/bin/bash

echo "===start to publish cpio for qemu==="
cd ~/infrastructure
chmod +x scripts/common_scripts/common.sh
source scripts/common_scripts/common.sh

set -e
set -o pipefail

function work() {
  echo "===start to build==="
  pip3 install -r ~/infrastructure/scripts/publish_pipeline/dailybuild/requirements.txt
  cd ~
  git clone https://gitcode.com/openUBMC/manifest.git
  cd manifest
  timeout 10m bingo build -sc qemu 2>&1 || true
  echo "===end to build successfully==="
  cd ~
  tar -czf conan_cache.tar.gz -C ~ .conan/data
  cp ~/infrastructure/scripts/utils/patch/client.py /usr/local/lib/python3.12/dist-packages/obs/client.py
  python3 ~/infrastructure/scripts/publish_pipeline/publish_conan/conan-cache.py --ak="$AK" --sk="$SK" --obs_endpoint="$ENDPOINT"
}

function main() {
  prepare_software
  prepare_npm_soft
  prepare_bingo
  prepare_git $GIT_USER $GIT_TOKEN
  prepare_conan $CONAN_USER $CONAN_PASSWORD
#  prepare_conan_cache
  work
}

main

exit 0